package com.egdd.video.controller;

import com.egdd.video.common.api.ApiResult;
import com.egdd.video.pojo.Audiocategory;
import com.egdd.video.service.iml.AudioCategoryServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = {"音频分类管理"})
@RequestMapping("/audioCategory")
public class AudioCategoryController{
    @Autowired
    AudioCategoryServiceImpl audioCategoryService;
    @ApiOperation("获取全部分类信息")

    @GetMapping(value = "/getAllAudiocategory")
    public ApiResult getAllAudiocategory() {
        List<Audiocategory> data = audioCategoryService.getAllAudiocategory();
        return ApiResult.success(data);
    }

    @ApiOperation("分页获取音频分类信息")
    @GetMapping(value = "/getAllAudiocategoryByPage")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "page",value = "页码信息",defaultValue = "1",paramType = "query"),
                    @ApiImplicitParam(name = "pageSize",value = "页码大小",defaultValue = "10",paramType = "query")
            }
    )
    public ApiResult getAllAudiocategoryByPage(int page, int pageSize) {
        List<Audiocategory> data = audioCategoryService.getAllAudiocategoryByPage(page,pageSize);
        return ApiResult.success(data);
    }

    @ApiOperation("删除音频分类信息")
    @GetMapping(value = "/delAudiocategoryById")
    public ApiResult delAudiocategoryById(int id) {
        int count = audioCategoryService.delAudiocategoryById(id);
        if (count==1){
            return ApiResult.success(count);
        }else {
            return ApiResult.success("操作失败");
        }
    }

    @ApiOperation("添加音频分类信息")
    @PostMapping(value = "/addAudiocategory")
    public ApiResult addAudiocategory(@RequestBody Audiocategory audiocategory) {
        int count = audioCategoryService.addAudiocategory(audiocategory);
        if (count==1){
            return ApiResult.success(count);
        }else {
            return ApiResult.success("操作失败");
        }
    }
}
